package com.example.shopp_2301

import android.os.Bundle
import android.view.KeyEvent
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.ToastUtils
import com.example.base.User
import com.example.base.mvvm.BaseActivity
import com.example.shopp_2301.databinding.ActivityMainBinding
import com.example.shopp_2301.login.LoginViewModel
import okhttp3.OkHttp

/**
 * 之前的主页，弃用
 */
@Route(path = "/app/MainActivity")
class MainActivity : BaseActivity<ActivityMainBinding,LoginViewModel>() {
    override fun initView() {
        viewModel.user()
        binding.update.setOnClickListener {
            ARouter.getInstance().build("/app/UpdatePwdActivity").navigation()
        }
    }

    override fun initData() {
        viewModel.userSuccess.observe(this){
            if(it.code==200){
                binding.info = it.data
            }else{
                ToastUtils.showLong(it.message)
            }
        }
        viewModel.userFail.observe(this){
            ToastUtils.showLong(it)
        }
    }

    override fun getViewModel(): Class<LoginViewModel> {
        return LoginViewModel::class.java
    }

    override fun getLayout(): Int {
        return R.layout.activity_main
    }
    //首页退出时，保存当前时间
    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        if(keyCode==KeyEvent.KEYCODE_BACK){//点击的按钮为退出键
            SPUtils.getInstance().put("time",System.currentTimeMillis())//保存退出时间
        }
        return super.onKeyDown(keyCode, event)
    }
}